package cn.lizemin.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author lzm
 * @Date 2024/7/27
 * @description 注意事项：每个servlet有自己独立的servlet配置，彼此之间互不影响
 * 这个servletConfig是Tomcat解析web.xml后，自动调用每个servlet的init(ServletConfig config)方法传进来的
 * 类似于spring的aware接口
 */
@WebServlet(urlPatterns = "/servlet7")
@MultipartConfig // 上传文件必须要使用这个注解才能够使用Part
public class MyServlet7 extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 设置响应行
//        resp.setStatus(404);

        // 设置响应头
        resp.setHeader("X-Csrf-Token", "123123");
        resp.setContentType("text/html;charset=utf-8");
        String info = "<h1>hello</h1>";
        resp.setContentLength(info.getBytes().length);

        PrintWriter writer = resp.getWriter();
        writer.println(info);

    }


}
